<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.javabean.*"%>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.model.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
<!--
body {
	background-color: #fff;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

.tabfont01 {
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}

.font051 {
	font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}

.font201 {
	font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}

.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}

html {
	overflow-x: auto;
	overflow-y: auto;
	border: 0;
}
-->
</style>

<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script src="../js/jquery-1.9.0.js"></script>
<script language="JavaScript" type="text/javascript">
	function selectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				obj[i].checked = true;
			}
		}
	}

	function unselectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				if (obj[i].checked == true)
					obj[i].checked = false;
				else
					obj[i].checked = true;
			}
		}
	}

	function link1() {
		document.getElementById("fom").action = "storeAdd.jsp";
		document.getElementById("fom").submit();
	}

	function link2() {
		document.getElementById("fom").action = "WP_Out.jsp";
		document.getElementById("fom").submit();
	}

	function storeDel(){
		var obj = document.fom.elements;
		var x = 0;
		for (var i=0; i<obj.length; i++ ){
		  if(obj[i].name == "delid"){
			  if(obj[i].checked == true){
				  x++;
			  }
		  }
		}
		if(x>0){
			document.getElementById("fom").method="post";
			document.getElementById("fom").action="StoreDeal?deal=delete";
			if(confirm("确定要删除选定库房？"))
				document.getElementById("fom").submit();
			}
		else{
			window.alert("请选择需要删除的库房");
			return;
		}
	}
	
	function go() {
		if($("#textfield3").val()==""||null){
			alert("请输入页数！");
			return;
		}
		var jump_page = document.getElementById("jump_page").value;
		location.href = "?pageCar=" + jump_page;
	}
</script>
</head>

<body>
	<%
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		int pageNow = 1;
		int pagePrev = 0;
		int pageNext = 0;
		int entityCount = 0;
		int pageSize = 10; //	the number of entities one page contains
							//	set as variable but not constant for future
							//	user-defined function.
		int pageTotal = 0;
		String query = request.getParameter("query");

		String pageNowStr = request.getParameter("pageStore");
		if (pageNowStr != null)
			pageNow = Integer.parseInt(pageNowStr);
		else
			; // initial value is 1

		Connection con = DataBase.getConnection();
		PreparedStatement pstmtCount = con
				.prepareStatement("SELECT COUNT(*) as count FROM item");
		ResultSet rs = pstmtCount.executeQuery();
		if (rs.next()) {
			entityCount = rs.getInt("count");
			int mod = entityCount % pageSize;
			if (mod == 0)
				pageTotal = entityCount / pageSize;
			else
				pageTotal = entityCount / pageSize + 1;
		} else {
			pageTotal = 1;
		}
		rs.close();

		if (pageNow > pageTotal || pageNow < 1)
			pageNow = 1;

		if (pageNow > 1)
			pagePrev = pageNow - 1;
		else
			; // initial value is 0

		if (pageNow < pageTotal)
			pageNext = pageNow + 1;
		else
			; // initial value is 0
		int userGrade = ((User) request.getSession(true).getAttribute(
				"user")).getUserGrade();
	%>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">

		<tr>
			<td height="30">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td height="62" background="../image/widgetbg5.jpg">
							<form name="search" id="search" method="get"
								action="WP_Storage.jsp">
								<table width="98%" border="0" align="center" cellpadding="0"
									cellspacing="0">
									<tr>
										<td width="24"><img src="../images/ico07.gif" width="20"
											height="18" /></td>
										<td width="519"><label>库房名称: <input name="query"
												id="query" type="text" nam="gongs" />
										</label> <input name="Submit" type="button" 
											value="查 询"
											onclick="document.getElementById('search').submit();" /></td>
										<td width="679" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
										</td>
									</tr>
								</table>
							</form>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>

			<td>
				<form name="fom" id="fom" method="post">
					<table id="subtree1" style="DISPLAY:" width="100%" border="0"
						cellspacing="0" cellpadding="0">
						<tr>
							<td><table width="95%" border="0" align="center"
									cellpadding="5" cellspacing="0">
									<tr>
										<td height="20"><span class="newfont07">选择：<a
												href="#" class="right-font08" onclick="selectAll();">全选</a>-<a
												href="#" class="right-font08" onclick="unselectAll();">反选</a></span>
											<input name="Submit" type="button" 
											value="添加库房" onclick="link1();" /> <input name="Submit2"
											type="button"  onclick="storeDel();"
											value="删除库房" />
											&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
										</td>
									</tr>
									<tr>
										<td height="40" class="font42"><table width="100%"
												border="0" cellpadding="4" cellspacing="1" bgcolor="#464646"
												class="newfont03">
												<tr>
													<td align="center" height="20" colspan="3" align="right"
														 class="tablestyle_title">物品库房列表</td>
												</tr>
												<tr>
													<td width="10%" align="center" class="zsd">选择</td>
													<td width="60%" height="20px" align="center"
														class="zsd">库房名称</td>
													<td width="20%" align="center" class="zsd">操作</td>
												</tr>
												<%
													PreparedStatement psStore;
													if(query==null){
														psStore=con.prepareStatement("SELECT * FROM store_room");
													}
													else{
														psStore=con.prepareStatement("SELECT * FROM store_room WHERE name LIKE ?");
														psStore.setString(1, "%"+query+"%");
													}
													ResultSet rsStore=psStore.executeQuery();
													while(rsStore.next()){%>
												<tr>
													<td height="20" bgcolor="#FFFFFF" align="center"><input
														type="checkbox" name="delid" id="delid" value="<%=rsStore.getString("name") %>"/></td>
													<td bgcolor="#FFFFFF" align="center"><a href="#">
													<%=rsStore.getString("name")+"("+rsStore.getString("room")+")" %>
													</a></td>
													<td bgcolor="#FFFFFF" align="center"><a
														href="<%="Storage_BJ.jsp?name="+URLEncoder.encode(URLEncoder.encode(rsStore.getString("name"), "UTF-8"), "UTF-8") %>">编辑</a></td>
												</tr>
												<%}
													rsStore.close();
													%>
											</table></td>
									</tr>
								</table></td>
						</tr>
					</table>
				</form>
				<table width="95%" border="0" align="center" cellpadding="0"
					cellspacing="0">
					<tr>
						<td height="6"><img src="../images/spacer.gif" width="1"
							height="1" /></td>
					</tr>
					<tr>
						<td height="33"><table width="100%" border="0" align="center"
								cellpadding="0" cellspacing="0" class="right-font08">
								<tr>
									<td width="50%">共 <span class="right-text09"><%=pageTotal%></span>
										页 | 第 <span class="right-text09"><%=pageNow%></span> 页
									</td>
									<td width="49%" align="right">[<a href="?pageStore=1"
										class="right-font08">首页</a> | <a
										href="<%="?pageStore=" + ((pagePrev == 0) ? pageTotal : pagePrev)%>"
										class="right-font08">上一页</a> | <a
										href="<%="?pageStore=" + ((pageNext == 0) ? 1 : pageNext)%>"
										class="right-font08">下一页</a> | <a
										href="<%="?pageStore=" + pageTotal%>" class="right-font08">末页</a>]
										转至：
									</td>
									<td width="1%"><table width="20" border="0"
											cellspacing="0" cellpadding="0">
											<tr>
												<td width="1%"><input id="textfield3" name="textfield3" type="text"
													class="right-textfield03" size="1" id="jump_page" /></td>
												<td width="87%"><input name="Submit23222" type="button"
													class="right-button06" value=" " onclick="go()" /></td>
											</tr>
										</table></td>
								</tr>
							</table></td>
					</tr>
				</table>

			</td>

		</tr>
	</table>
</body>
<%
	con.close();
%>
</html>
